Vue.component('homeqad', {
    template: `
      <div class="ques-and-ans">
        <template v-if="isData">
              <div class="qa-header" v-if="recommentQuestion.length">
                  <p class="qa-tip">问答（{{allQuestionTotal}}）</p>
                  <a class="qa-lookall" href="quesAndAns.html" @click="showStat">查看全部<img class="arrow-icon" :src="hxmConfig.arrowRightImgUrl"/></a>
                </div>
                <div class="qa-header" v-else>
                  <p class="qa-tip">问答</p>
                </div>
                <dl class="ques-wrap" v-if="recommentQuestion.length">
                  <dd class="home-ques"
                      @click="jump"
                      v-for="(itemQA,index) in recommentQuestion"
                      :key="itemQA.id">{{itemQA.questionContent}}
                  </dd>
                </dl>
                <p class="ques-wrap" style="text-align: center" v-else>
                    暂无相关数据~~
                </p>
        </template>
        <template v-else>
              <p class="leaderLoading loading"><img class="loading-img" :src="hxmConfig.loadingImgUrl"alt=""></p>
        </template>
        
      </div>`,

    data() {
        return {
            allQuestionTotal: null,
            recommentQuestion: [],
            isData:false,
        }
    },
    created() {
        this.initData()
    },
    methods: {
        jump(){
          window.location.href = 'quesAndAns.html'
          this.showStat()
        },
        //埋点
        showStat(){
            thsStats.clickStat('index', 'wenda.click')
        },
        //判断文本是否多出
        initData() {
            let _this = this
            ajax(hxmConfig.entranceApi, {},
                function (res) {
                    if (res.status_code == 0) {
                        _this.allQuestionTotal = res.data.allQaTotal
                        _this.recommentQuestion = res.data.topQaList
                        _this.isData = true
                    } else {
                        _this.isData = false
                    }
                },
                function (err) {
                    _this.isData = false
                }
            )
        }
    },
})